package com.hucheng.goods.vo;

import com.hucheng.goods.entity.CartDO;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.format.DateTimeFormatter;

/**
 * @Author: 凉白开不加冰
 * @Version: 0.0.1V
 * @Date: 2019-06-25
 * @Description: 返回界面数据
 **/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CartVO implements Serializable{
    private Integer cartId;
    private Integer userId;
    private Integer goodsId;
    private Integer goodsNumber;
    private Integer isDel;
    private String dateCreated;
    private String dateUpdated;

    public static CartVO buildCartVO(final CartDO cartDO) {
        if (cartDO == null) {
            return null;
        }
        DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        return new CartVO(cartDO.getCartId(),cartDO.getUserId(),cartDO.getGoodsId(),cartDO.getGoodsNumber(),cartDO.getIsDel(),
                dateTimeFormatter.format(cartDO.getDateCreated().toLocalDateTime()),
                dateTimeFormatter.format(cartDO.getDateUpdated().toLocalDateTime()));
    }
}
